using System;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using DevExpress.CodeRush.Core;
using DevExpress.CodeRush.PlugInCore;
using DevExpress.CodeRush.StructuralParser;
using System.Diagnostics;
using System.Collections.Generic;

namespace DX_SourceOutliner
{
    public class TreeProcessor
    {
        private IEnumerable<ITreeProcessor> _treeProcessors;
        public TreeProcessor(IEnumerable<ITreeProcessor> treeProcessors)
        {
            _treeProcessors = treeProcessors;

        }

        public IEnumerable<TreeNode> Process(IEnumerable<TreeNode> nodes)
        {
            if (_treeProcessors.Count() == 0)
                return nodes;

            var returnNodes = nodes.ToList();

            foreach (ITreeProcessor processor in _treeProcessors)
            {
                var processedNodes = new List<TreeNode>();

                foreach (TreeNode node in processor.Process(nodes))
                {
                    if (!processedNodes.Contains(node))
                        processedNodes.Add(node);

                }

                foreach (TreeNode node in nodes)
                {
                    if (!processedNodes.Contains(node))
                        returnNodes.Remove(node);
                }

            }

            return returnNodes;
        }

    }
}
